package com.atlassian.tutorial.listener;

import com.atlassian.confluence.event.events.security.LoginEvent;
import com.atlassian.confluence.event.events.security.LogoutEvent;
import com.atlassian.event.api.EventListener;
import com.atlassian.event.api.EventPublisher;
import com.atlassian.plugin.spring.scanner.annotation.component.Scanned;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author gaowl@stu.jiangnan.edu.cn
 * @version 2021/07/02/14:45
 */
@Scanned
public class UserLogoutEventListener implements DisposableBean {

    @ComponentImport
    private final EventPublisher eventPublisher;

    @Autowired
    public UserLogoutEventListener(EventPublisher eventPublisher) {  // 通过构造函数注入成员变量
        this.eventPublisher = eventPublisher;
        this.eventPublisher.register(this);   // 注册监听eventPublisher的事件监听器
    }

    @EventListener
    public void UserLogoutEventDemo(LogoutEvent logoutEvent){
        System.out.println("================= 请客，===============");
        System.out.println("================= 砍头，===============");
        System.out.println("=============== 收下当狗 ===============");
        System.out.println("============= 项羽请刘邦啊 ==============");
    }


    @Override
    public void destroy() throws Exception {
        this.eventPublisher.unregister(this);
    }
}
